package cn.tedu.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.thymeleaf.context.Context;

import cn.tedu.dao.EmpDao;
import cn.tedu.entity.Emp;
import cn.tedu.entity.User;
import cn.tedu.utils.ThyUtils;

/**
 * Servlet implementation class ListServlet
 */
public class ListServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("小红桃");
		//获取Session中登录用户信息
		//如果有登录信息,则继续显示员工列表
		//若果没有登录信息,则重定向login.html
		/*HttpSession session=request.getSession();
		User user=(User)session.getAttribute("loginUser");
		if(user==null) {
			//没有登录
			String path=request.getContextPath()+"/login.html";
			response.sendRedirect(path);
			return;
		}*/
		
		//通过dao查询所有的员工信息
		EmpDao dao=new EmpDao();
		List<Emp> emps=dao.findAll();
		//System.out.println(emps);
		Context context=new Context();
		context.setVariable("emps", emps);
		ThyUtils.write("list", response, context);
	}
}
